<?php
require_once("db/db_connector.php");
require_once("db/db_paradise.php");
require_once("db/db_picture.php");
require_once("db/db_video.php");

$id = FALSE;
$picture = TRUE;
$video = TRUE;
$keyword = NULL;

if (isset($_GET["id"])) {
	$id = $_GET["id"];
}

if (isset($_GET["picture"])) {
	$picture = $_GET["picture"] == 1;
}

if (isset($_GET["video"])) {
	$video = $_GET["video"] == 1;
}

if (isset($_GET["keyword"])) {
	$keyword = $_GET["keyword"];
}

// Database Access Begins ---------------------------------------- //
$con = get_db_con();
$paradise =  get_paradise($con, $id);
if ($picture) {
	$picture_list = get_picture_list($con, $id, FALSE, $keyword);
}

if ($video) {
	$video_list = get_video_list($con, $id, FALSE, $keyword);
}
close_db_con();
// Database Access Ends ------------------------------------------ //

?>

<?php
include_once("include/header.php");
?>

<h1><?=$paradise["name"]?> Gallery</h1>

<div>
	<form action="paradise_gallery.php" method="get">
		<input type="hidden" name="id" value="<?=$id?>" />
		<input type="hidden" name="picture" value="<?=$picture?>" />
		<input type="hidden" name="video" value="<?=$video?>" />
		<input type="text" name="keyword" value="<?=$keyword?>" />
		<button type="submit">Search</button>
	</form>
</div>

<div>
	<a href="paradise_gallery.php?id=<?=$paradise["id"] ?>&picture=1&video=1&keyword=<?=$keyword?>">Show Both</a> |
	<a href="paradise_gallery.php?id=<?=$paradise["id"] ?>&picture=1&video=0&keyword=<?=$keyword?>">Pictures Only</a> |
	<a href="paradise_gallery.php?id=<?=$paradise["id"] ?>&picture=0&video=1&keyword=<?=$keyword?>">Videos Only</a>
</div>

<?php if ($picture) :?>
	<h2>Pictures</h2>
	<div>
		<?php if (count($picture_list) > 0) :?>
			<?php foreach ($picture_list as $picture) :?>
				<div style="float:left; margin-right:1em;">
					<img src="<?=$picture["thumb_small"]?>" />
					<div style="text-align:center">
						<a href="<?=$picture["url"] ?>" class="lightbox slides">
							<?=$picture["title"]?>
						</a>
					</div>
				</div>
			<?php endforeach ?>
		<?php else :?>
			<p>No Result Found</p>
		<?php endif ?>
	</div>
	<div style="clear:both;"></div>
<?php endif ?>

<?php if ($video) :?>
	<h2>Videos</h2>
	<div>
		<?php if (count($video_list) > 0) :?>
			<?php foreach ($video_list as $video) :?>
				<div style="float:left; margin-right:1em;">
					<img src="http://img.youtube.com/vi/<?=$video["youtube_id"]?>/mqdefault.jpg" />
					<div style="text-align:center">
						<a href="http://www.youtube.com/embed/<?=$video["youtube_id"] ?>?rel=0&amp;wmode=transparent" class="youtube slides">
							<?=$video["title"]?>
						</a>
					</div>
				</div>
			<?php endforeach ?>
		<?php else :?>
			<p>No Result Found</p>
		<?php endif ?>
	</div>
	<div style="clear:both;"></div>
<?php endif ?>

<?php
include_once("include/footer.php");
?>
